﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Ionic.Zip;

namespace LegSec.NugetThirdPartyLicenseFileGenerator
{
    public class NupkgReader
    {
        public static void ExtractNspecFilesToDirectory(List<FileInfo> nupkgFiles, string rootDierectory)
        {
            foreach (var nupkgFile in nupkgFiles)
            {
                var openedFile = ZipFile.Read(nupkgFile.FullName);
                foreach (var zipEntry in openedFile.Entries)
                {
                    if (zipEntry.FileName.EndsWith(".nuspec"))
                    {
                        zipEntry.Extract(rootDierectory, ExtractExistingFileAction.OverwriteSilently);
                    }
                }
            }
        }
    }
}
